#include "Simulation.h"

Simulation::Simulation()
{
	reg = new RegPolygon();
	part = Particle();
	stepFrac = 0.001;
}

Simulation::Simulation(Region* region, double stepFraction)
{
	reg = region;
	part = Particle();
	stepFrac = stepFraction;
}

Simulation::Simulation(Region* region, double stepFraction, double particleX, double particleY)
{
	reg = region;
	part = Particle(particleX,particleY);
	stepFrac = stepFraction;
}

Simulation::~Simulation()
{
	delete reg;
}

int Simulation::run()
{
	int steps = 0;
	double originalPosX = part.position[0];
	double originalPosY = part.position[0];
	
	//Run until the particle leaves the designated region
	while(reg->pointInside(part.position))
	{
		part.randomMove(stepFrac);
		steps++;
	}

	//Reset for additional simulations
	part.setPosition(originalPosX,originalPosY);

	return steps;
}

void Simulation::save_data_to_csv_file(int * data, int runs, char *filename)
{
	ofstream ofs(filename,ios::binary);
	assert(ofs);
	for(int i=1; i<runs; i++)
    {
		ofs << data[i] << endl;
    }
}

void Simulation::save_data_to_csv_file(int * data, int runs, float runtime, char *filename)
{
	ofstream ofs(filename,ios::binary);
	assert(ofs);
	ofs << data[0] << " " << runtime << endl;
	for(int i=1; i<runs; i++)
    {
		ofs << data[i] << endl;
    }
}